import { defHttp } from '/@/utils/http/axios';
import { Modal } from 'ant-design-vue';
enum Api {
  LIST_URL = '/system/menu/table',
  SAVE_URL = '/system/menu/create',
  UPDATE_URL = '/system/menu/update',
  DELETE_URL = '/system/menu/delete',
  DELETE_BATCH_URL = '/system/dicts/deleteBatch',
  QUERY_MENU_PERMISSION_URL = '/system/menu/permissions',
}

/**
 * 列表接口
 * @param params
 */
export const getMenuList = (params) => defHttp.get({ url: Api.LIST_URL, params });

/**
 * 删除菜单
 */
export const deleteById = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.DELETE_URL + `/${params.id}` }).then(() => {
    handleSuccess();
  });
};
/**
 * 批量删除菜单
 * @param params
 */
export const batchDeleteMenu = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp
        .delete({ url: Api.DELETE_BATCH_URL, data: params }, { joinParamsToUrl: true })
        .then(() => {
          handleSuccess();
        });
    },
  });
};
/**
 * 保存或者更新
 * @param params
 * @param isUpdate
 */
export const saveOrUpdateMenu = (params, isUpdate) => {
  const url = isUpdate ? Api.UPDATE_URL : Api.SAVE_URL;
  return defHttp.post({ url: url, params });
};

/**
 * 查询菜单权限
 */
export const queryMenuPermission = (params) =>
  defHttp.get({ url: Api.QUERY_MENU_PERMISSION_URL, params });

/**
 * 删除菜单
 */
export const deletePermsById = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.DELETE_URL + `/${params.id}` }).then(() => {
    handleSuccess();
  });
};
